var db = require('./dirtleWrapper');
var USER_TABLE_NAME = 'user';

// make sure the Note table is created
db.createTable(USER_TABLE_NAME);

function User(name, pass) {
    this.name = name;
    this.pass = pass;
}

function addUser(name, pass) {
    console.log("Adding user : " + name);
    db.insertItem(USER_TABLE_NAME, new User(name, pass));
}
exports.addUser = addUser;

function getUserById(user_id) {
    return db.findItemById(USER_TABLE_NAME, user_id);
}
exports.getUserById = getUserById;

function removeUser(user_id) {
    //db.removeItem
}
exports.removeUser = removeUser;

function getUserByLogin(login) {
	var userArray = db.selectItems(USER_TABLE_NAME, ['name'], [login]);
	if (userArray != null && userArray.length == 1) {
		return userArray[0];
	} else {
		console.log("Unable to find user with login : " + login)
		return null;
	}
}
exports.getUserByLogin = getUserByLogin;